/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 072. 求平方根
 * @author: WXY
 * @create: 2023-01-10 09:44
 * @Version 1.0
 **/
public class offer_twentyfour2_mySqrt {
    public static int mySqrt(int x) {
        if (x == 0 || x == 1) {
            return x;
        }
        int l = 1;
        int r = x / 2;
        while (l <= r) {
            int mid = l + (r - l) / 2;
            if (mid <= x / mid) {
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        return l - 1;
    }
}
